package com.ysy.tz.mfg.component;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import org.apache.commons.lang3.StringUtils;

public class PigGradingLabel extends VBox {
    private Label prompLabel = new Label();
    private StringProperty prompProperty = new SimpleStringProperty();

    public PigGradingLabel() {
        Label defaultLabel = new Label();
        defaultLabel.setStyle("-fx-font-size: 18; -fx-font-weight: bold;-fx-padding: 5 0 0 0;");
        defaultLabel.setAlignment(Pos.CENTER);
        defaultLabel.prefWidthProperty().bind(this.widthProperty());
        this.getChildren().add(defaultLabel);
        this.prompLabel.setStyle("-fx-font-size: 10; -fx-font-style:italic;-fx-text-fill:rgb(170,170,170);");
        this.prompLabel.setAlignment(Pos.CENTER);
        this.prompLabel.prefWidthProperty().bind(this.widthProperty());
        this.prompLabel.setVisible(false);
        this.prompLabel.setManaged(false);
        this.getChildren().add(this.prompLabel);
        this.prompProperty.addListener(new ChangeListener<String>() {
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                if (StringUtils.isNotBlank(newValue)) {
                    PigGradingLabel.this.prompLabel.setText(newValue);
                    PigGradingLabel.this.prompLabel.setManaged(true);
                    PigGradingLabel.this.prompLabel.setVisible(true);
                }

            }
        });
        this.setManaged(false);
        this.setVisible(false);
    }

    public void setValue(String... value) {
        if (value != null && value.length > 0) {
            int count = value.length - (this.getChildren().size() - 1);

            int i;
            for(i = 0; i < count; ++i) {
                Label defaultLabel = new Label();
                defaultLabel.setStyle("-fx-font-size: 18; -fx-font-weight: bold;");
                defaultLabel.setAlignment(Pos.CENTER);
                defaultLabel.prefWidthProperty().bind(this.widthProperty());
                this.getChildren().add(1, defaultLabel);
            }

            for(i = 0; i < value.length; ++i) {
                ((Label)this.getChildren().get(i)).setText(value[i]);
            }

            this.setManaged(true);
            this.setVisible(true);
        } else {
            this.setManaged(false);
            this.setVisible(false);
        }
    }

    public void select(boolean select) {
        int i;
        if (select) {
            ((Label)this.getChildren().get(0)).setStyle("-fx-font-size: 18; -fx-font-weight: bold;-fx-padding: 5 0 0 0;-fx-text-fill: rgb(207,71,63)");

            for(i = 1; i < this.getChildren().size() - 1; ++i) {
                ((Label)this.getChildren().get(i)).setStyle("-fx-font-size: 18; -fx-font-weight: bold;-fx-text-fill: rgb(207,71,63)");
            }

            ((Label)this.getChildren().get(this.getChildren().size() - 1)).setStyle("-fx-font-size: 10; -fx-font-style:italic;-fx-text-fill: rgb(207,71,63)");
        } else {
            ((Label)this.getChildren().get(0)).setStyle("-fx-font-size: 18; -fx-font-weight: bold;-fx-padding: 5 0 0 0;");

            for(i = 1; i < this.getChildren().size() - 1; ++i) {
                ((Label)this.getChildren().get(i)).setStyle("-fx-font-size: 18; -fx-font-weight: bold;");
            }

            ((Label)this.getChildren().get(this.getChildren().size() - 1)).setStyle("-fx-font-size: 10; -fx-font-style:italic;-fx-text-fill:rgb(170,170,170);");
        }

    }

    public String getPrompProperty() {
        return (String)this.prompProperty.get();
    }

    public StringProperty prompPropertyProperty() {
        return this.prompProperty;
    }

    public void setPrompProperty(String prompProperty) {
        this.prompProperty.set(prompProperty);
    }
}
